<template>
    <el-dialog title="收货地址" :visible.sync="showEditDialog">
        <div v-for="(add,index) in selectMessage" :key="index">
            <el-button  @click="mrAddr(index);showEditDialog = false">删除</el-button>
            <span>{{add}}</span>
            <el-button style="float: right;" @click="updateaddr(add);showEditDialog = false">更换</el-button>
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button @click="showEditDialog = false">完成</el-button>
        </div>
    </el-dialog>
</template>

<script>
// import axios from 'axios'
import http from "../../core/HttpRequest"
export default {
    // props:['sendData'],
    data: () => ({
        selectMessage:[],
        showEditDialog: false,
        name:'',
        userId:'',
        addr:[],
    }),
    mounted:function(){
         let uname =this.$cookies.get("username")
         this.name = uname
         let username = new URLSearchParams()
         username.append('userName', this.name),
          http({
              method: "post",
              url: `/orderNum/id`,
              data: username
          })
        .then(res => {
            this.userId = res.data.data
            this.userss()
        })
    },
    methods: {
        userss(){
            let address = new URLSearchParams()
         address.append('userId', this.userId), 
          http({
              method: "post",
              url: `/orderNum/select`,
              data: address
          })
          .then(res=> {
              this.addr = res.data.data
            for(var i=0;i<this.addr.length;i++){
                this.selectMessage[i]=this.addr[i].receiverName+'  '+this.addr[i].receiverMobile+'   '+this.addr[i].province+'   '+this.addr[i].city+'   '+this.addr[i].area+'  '+ this.addr[i].addr
            }
            console.log(this.selectMessage);
            this.movies = res.data.data.hot
          })
        },
        updateaddr(add) {
        let data = {  
          newaddr: add  
        };  
        this.$emit('showaddr',data)
        },
        //删除地址
        mrAddr(index){
            let addrId = this.addr[index].addrId
            let addre = new URLSearchParams()
            addre.append('addrId', addrId),  
             http({
              method: "post",
              url: `/orderNum/rmAddr`,
              data: addre
          })
          .then(res=> {
              console.log(res);
              this.shuaxin()
            //   this.userss()
          })
        },
        shuaxin() {
            location.reload()
            }
    },
}
</script>

<style>

</style>